<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="js/axios.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/jquery-1.7.2.min.js"></script>


</head>
<body>
<div id="app">
        <form>
          <input  type="text" name="name" id="name"  v-model="vusername" placeholder="用户名">
            <br>
            <input  type="text"  name="password" id="password" v-model="vpassword" placeholder="密码">
            <br>
            <input @click="login" type="button" value="登录">
        </form>
</div>
<script >
new Vue({
    el: "#app",
    data: {
        token: "", //接收token
        vusername: "" ,//接收用户名
        vpassword: "",
        msg: "" //用来接收登录成功
    },
    methods: {
        login:function () {

            if (this.vusername == "") {
                alert("用户名不能为空")
                return false
            } else if (this.vpassword == "") {
                alert("密码不能为空")
                return false
            } else {
                console.log('准备登录')
                console.log(this.vusername)
                console.log(this.vpassword)
                var that=this;
                axios.post("/login?name="+this.vusername+"&password="+this.vpassword).then(function (response) {
                    console.log(response);
                    that.token=response.data

                    if( that.token!=""){
                        axios.post("/cheaktoken?token="+that.token).then(
                            function (response) {
                                console.log(response)
                                that.msg=response.data;
                                if(that.msg!=""){
                                    $.ajax({
                                        type: "GET",
                                        url: "/mymusic" ,
                                        headers: {'Authorization': token}
                                    });
                                }


                            }
                        )
                    }


                }).catch(function (erro) {
                    console.log("出错了")

                })
            }
        }


        }



})
// $.ajax({
//     type: "post",
//     url: "/mymusic" ,
//     headers: {'Authorization': that.token}
// });
</script>
</body>
</html>